home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Geek Games #12
/
GEGA012.iso
/
Jogos de Azar
/
fruit.swf
/
scripts
/
C_BalanceMashine.as
next >
Wrap
Text File
|
2006-01-17
|
4KB
|
182 lines
_global.C_BalanceMashine = function()
{
this.init();
this.drawBalance();
};
C_BalanceMashine.prototype = new MovieClip();
C_BalanceMashine.prototype.init = function()
{
this._x = Math.round(this._x);
this._y = Math.round(this._y);
this.comma_mc._visible = 0;
var o;
var t;
this.c_array = [];
this.c_array[0] = this.C1_mc;
this.c_array[1] = this.C2_mc;
var i = 0;
while(i < this.c_array.length)
{
t = this.c_array[i];
t._x = Math.round(t._x);
t._y = Math.round(t._y);
t.number_new = 0;
i++;
}
this.S4_mc.isComma = true;
this.d_array = [];
this.d_array[0] = this.S1_mc;
this.d_array[1] = this.S2_mc;
this.d_array[2] = this.S3_mc;
this.d_array[3] = this.S4_mc;
this.d_array[4] = this.S5_mc;
this.d_array[5] = this.S6_mc;
var i = 0;
while(i < this.d_array.length)
{
t = this.d_array[i];
t._x = Math.round(t._x);
t._y = Math.round(t._y);
t.number_new = 0;
i++;
}
};
C_BalanceMashine.prototype.addProperty("balance",function()
{
return this._balance;
}
,function(b)
{
this._balance = b;
this.drawBalance();
}
);
C_BalanceMashine.prototype.drawBalance = function()
{
this.animTargets = 0;
var centes = String(Math.floor(this._balance * 100)).substr(-2);
if(centes.length < 2)
{
centes = "0" + centes;
}
var i = 0;
while(i < this.c_array.length)
{
this.drawNumber(this.c_array[i],centes.substr((i + 1) * -1,1));
i++;
}
var dollars = " " + String(Math.floor(this._balance));
var i = 0;
while(i < this.d_array.length)
{
this.drawNumber(this.d_array[i],dollars.substr((i + 1) * -1,1));
i++;
}
};
C_BalanceMashine.prototype.drawNumber = function(targ, n)
{
var number_new = n != " " ? Number(n) : 0;
var number_old = targ.number_new != " " ? targ.number_new : 0;
var a = targ.eventsArray = [];
if(targ.number_new == n || isNaN(number_new))
{
return undefined;
}
if(number_new == number_old)
{
if(n == " ")
{
a.push({event:"BACK",number_old:0,number_new:" "});
}
else
{
a.push({event:"FORWARD",number_old:" ",number_new:0});
}
}
else
{
var d;
var event;
var p = Math.abs(number_new - number_old) <= 5;
if(number_new > number_old)
{
if(p)
{
event = "FORWARD";
d = 1;
}
else
{
event = "BACK";
d = -1;
}
}
else if(!p)
{
event = "FORWARD";
d = 1;
}
else
{
event = "BACK";
d = -1;
}
if(targ.number_old == " ")
{
a.push({event:"FORWARD",number_old:" ",number_new:0});
}
var cur_number = number_old;
while(cur_number != number_new)
{
number_old = cur_number;
cur_number += d;
if(cur_number > 9)
{
cur_number = 0;
}
else if(cur_number < 0)
{
cur_number = 9;
}
a.push({event:event,number_old:number_old,number_new:cur_number});
}
if(n == " ")
{
a.push({event:"BACK",number_old:0,number_new:" "});
}
}
if(a.length)
{
this.animTargets = this.animTargets + 1;
Conv.stop();
}
if(targ.stoped)
{
this.onEvent(targ);
}
};
C_BalanceMashine.prototype.onEvent = function(targ)
{
var a = targ.eventsArray;
if(a.length == 0)
{
targ.stoped = true;
if(--this.animTargets <= 0)
{
Conv.play();
}
return undefined;
}
targ.stoped = false;
var e = a.shift();
targ.number_old = e.number_old;
targ.number_new = e.number_new;
targ.gotoAndPlay(e.event);
if(targ.isComma)
{
this.comma_mc._visible = e.number_new != " ";
}
};
Object.registerClass("C_BalanceMashine",C_BalanceMashine);
ASSetPropFlags(_global,"C_BalanceMashine",131);